<include file="Public/head"/>
<body class="no-skin">
<include file="Public/header"/>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <include file="Public/sidebar"/>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <include file="Public/breadcrumbs"/>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                <include file="Public/set"/>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="row">
                            <form class="form-inline" action="" method="get">
                                <a class="btn btn-info" href="{:U('add')}" value="">新增</a>
                                <label class="inline">账户搜索</label>
                                <select name="field" class="form-control">
                                    <option <if condition="I('field') eq user">selected</if> value="user">账户名</option>
                                    <option <if condition="I('field') eq phone">selected</if> value="phone">电话</option>
                                    <option <if condition="I('field') eq qq">selected</if> value="qq">QQ</option>
                                    <option <if condition="I('field') eq email">selected</if> value="email">邮箱</option>
                                </select>
                                <input type="text" name="keyword" value="{:I(keyword)}" class="form-control">
                                <label class="inline">&nbsp;&nbsp;排序：</label>
                                <select name="order" class="form-control">
                                    <option <if condition="I('order') eq asc">selected</if> value="asc">注册时间升</option>
                                    <option <if condition="I('order') eq desc">selected</if> value="desc">注册时间降</option>
                                </select>
                                <button type="submit" class="btn btn-purple btn-sm">
                                    <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
                                    Search
                                </button>
                            </form>

                        </div>
                        <div class="space-4"></div>
                        <div class="row">
                            <form id="form" method="post" action="{:U('del')}">
                                <table class="table table-striped table-bordered table-hover">
                                    <thead>
                                    <tr>
										<if condition="$login_gid eq 1">
										<th class="center one"> ID</th>
										</if>
                                        <th>账户名</th>
										<if condition="$login_gid eq 1">
                                        <th>权限组</th>
										</if>
                                        <th class="center">电话</th>
                                        <th class="center">Q&nbsp;Q</th>
										<if condition="$login_gid eq 1">
										<th class="center">支付类型</th>
										<th class="center">支付姓名</th>
                                        <th class="center">支付帐号</th>
                                        <th class="center">余额</th>
										<else/>
										<th class="center">开户人</th>
										</if>
                                        <th class="center">分成比例</th>
										<th class="center">注册时间</th>
										<th class="center">状态</th>
										<th class="center">等级</th>
                                        <th class="center">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <style>
                                        .grouptd {
                                            position: relative;
                                        }

                                        .group {
                                            display: inline-block;
                                            width: 100%;
                                        }

                                        .groupselect {
                                            position: absolute;
                                            top: 0;
                                            left: 0;
                                            width: 100%;
                                            height: 100%;
                                            border: 0;
                                        }
                                    </style>
                                    <volist name="list" id="val">
										<if condition="$login_gid eq 1 && $val['has_child']">
										<tr class="has_child c_hide" data-id="{$val['uid']}">
										<else/>
										<tr>
										</if>
											<if condition="$login_gid eq 1">
											<td class="one"><i onclick="getchildren(this)"></i>{$val['uid']}
												<input class="uids" type="hidden" name="uids[]" value="{$val['uid']}">
											</td>
											</if>
                                            <td>{$val['user']}</td>
											<if condition="$login_gid eq 1">
                                            <td class="grouptd">
                                                <span class="group" val="{$val['uid']}">{$val['title']}</span>
                                            </td>
											</if>
                                            <td class="center">{$val.phone|default='<span class="text-danger">未填写</span>'}</td>
                                            <td class="center">{$val.qq|default='<span class="text-danger">未填写</span>'}</td>
											<if condition="$login_gid eq 1">
											<td class="center">
												<if condition="$val.account_type eq 1">
												<font color="#03A9F4">支付宝</font>
												<elseif condition="$val.account_type eq 2"/>
												<font color="#0baf11">微信</font>
												<elseif condition="$val.account_type eq 3"/>
												<font color="#FFC107">银行卡</font>
												</if>
											</td>
											<td class="center">{$val.truename|default='<span class="text-danger">未填写</span>'}</td>
                                            <td class="center">{$val.alipay|default='<span class="text-danger">未填写</span>'}</td>
                                            <td class="center">{$val.money}</td>
											<else/>
											<td class="center">{$val.truename|default='<span class="text-danger">未填写</span>'}</td>
											</if>
                                            <td class="center">{$val.proportion}%</td>
											<td class="center">{$val['t']|date='Y-m-d H:i:s' , ###}</td>
											<td class="center">
												<if condition="$val.is_lock eq 1">
												<span class="hierarchy_default hierarchy_fine">正常</span>
												<else/>
												<span class="hierarchy_default">禁用</span>
												</if>
											</td>
											<td class="center">
												<if condition="$val.hierarchy eq 2">
												<span class="hierarchy_default">差</span>
												<elseif condition="$val.hierarchy eq 3"/>
												<span class="hierarchy_default hierarchy_good">良</span>
												<elseif condition="$val.hierarchy eq 4"/>
												<span class="hierarchy_default hierarchy_fine">优</span>
												<else/>
												<span class="hierarchy_default">待定</span>
												</if>
											</td>
                                            <td class="center">
												<a class="hierarchy_default hierarchy_fine" href="{:U('Stats/order',array('uid'=>$val['uid']))}"><i class="fa fa-bar-chart-o"></i>&nbsp;数据统计</a>
												&nbsp;
												<div class="btn-group" style="vertical-align: top;">
													<a class="hierarchy_default hierarchy_fine" data-toggle="dropdown" aria-expanded="false">
														更多 <span class="caret"></span>
													</a>
													<ul class="dropdown-menu dropdown-menu-right">
														<!--<li>
															<a href="/backend/referral_links/index?uid={$val['uid']}"><i class="fa fa-list"></i> 推广链接</a>
														</li>											
														<li class="divider"></li>-->
														<li>
															<a href="{:U('edit',array('uid'=>$val['uid']))}"><i class="fa fa-edit"></i> 修改资料</a>
														</li>
														<li class="divider"></li>
														<li>
															<a data-id="{$val['uid']}" data-name="{$val['user']}" data-toggle="reset-password" href="#" class="text-danger reset_pass" onclick="reset_password(this)"><i class="fa fa-key"></i> 重置密码</a>
														</li>
														<if condition="$login_gid eq 1 || $UserJurisdiction['if_user_lock'] eq 1">
														<li class="divider"></li>
														<li>
															<if condition="$val['is_lock'] neq 1">
															<a href="javascript:set_lock({$val['uid']},1)" title="取消禁用"><i class="fa fa-unlock"></i> 取消禁用</a>
															<else/>
															<a href="javascript:set_lock({$val['uid']},2)" title="禁用"><i class="fa fa-lock"></i> 禁用账户</a>
															</if>
														</li>
														</if>
													</ul>
												</div>
                                            </td>
                                        </tr>
                                    </volist>
                                    </tbody>
                                </table>
                            </form>
                            
                            {$page}
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <include file="Public/footer"/>
	<!-- 模态框（Modal） -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
							&times;
					</button>
					<h4 class="modal-title" id="myModalLabel"></h4>
				</div>
				<div class="modal-body"></div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default btn_un" data-dismiss="modal">取消</button>
					<button type="button" class="btn btn-primary btn_ok" data-dismiss="modal">确定</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
	</div>
</div><!-- /.main-container -->

<include file="Public/footerjs"/>
<!-- inline scripts related to this page -->
<script type="text/javascript">
	var login_gid = '{$login_gid}';
    $(function () {
        $(".uids").click(function () {
            var option = $(".ids");
            option.each(function (i) {
                if (!this.checked) {
                    $(".check-all").prop("checked", false);
                    return false;
                } else {
                    $(".check-all").prop("checked", true);
                }
            });
        });
		
    })
	/**
	* 获取下级列表
	**/
	function getchildren(obj){
		var t = $(obj).closest("tr");
		var id = t.attr('data-id');
		var child = $(".child_" + id);
		var field = $("select[name=field]").val();
		var keyword = $("input[name=keyword]").val();
		if(t.hasClass('c_hide')) {
			if (child.length > 0) {
				child.show()
				t.removeClass('c_hide').addClass('c_open');
			} else{
				$.get("{:U('childrenlist')}?uid="+id+'&field='+field+'&keyword='+keyword,
						function(data){
							var ret = JSON.parse(data);
							var html = '';
							
							var nbsp_html = '';
							for(var i=0;i<ret.level;i++){
								nbsp_html += '&nbsp;&nbsp;&nbsp;&nbsp;';
							}
							
							for(var i in ret.list){
								//判断支付账号类型
								var account_type_font = '<font color="#03A9F4">支付宝</font>';
								if(ret.list[i]['account_type']==2){
									account_type_font = '<font color="#0baf11">微信</font>';
								}else if(ret.list[i]['account_type']==3){
									account_type_font = '<font color="#FFC107">银行卡</font>';
								}
								var default_con = '<span class="text-danger">未填写</span>';
								
								var lock_font = '<span class="hierarchy_default">禁用</span>';
								if(ret.list[i]['is_lock'] == 1){
									lock_font = '<span class="hierarchy_default hierarchy_fine">正常</span>';
								}
								
								var hierarchy_font = '<span class="hierarchy_default">待定</span>';
								if(ret.list[i]['hierarchy'] == 2){
									hierarchy_font = '<span class="hierarchy_default">差</span>';
								}else if(ret.list[i]['hierarchy'] == 3){
									hierarchy_font = '<span class="hierarchy_default hierarchy_good">良</span>';
								}else if(ret.list[i]['hierarchy'] == 4){
									hierarchy_font = '<span class="hierarchy_default hierarchy_fine">优</span>';
								}
								
								var lock_set_font = '';
								if(login_gid == '1' || ret.UserJurisdiction['if_user_lock'] == 1){
									lock_set_font +='<li class="divider"></li><li>';
									if(ret.list[i]['is_lock'] != 1){
										lock_set_font +='<a href="javascript:set_lock('+ret.list[i]['uid']+',1)" title="取消禁用"><i class="fa fa-unlock"></i> 取消禁用</a>';
									}else{
										lock_set_font +='<a href="javascript:set_lock('+ret.list[i]['uid']+',2)" title="禁用"><i class="fa fa-lock"></i> 禁用账户</a>';
									}
									lock_set_font +='</li>';
								}
							
								if(login_gid == '1' && ret.list[i]['has_child']){
									html +='<tr class="has_child c_hide child_'+id+'" data-id="'+ ret.list[i]['uid'] +'">';
								}else{
									html +='<tr class="child_'+id+'">';
								}
								
								
								
								html +='<td class="one">' + nbsp_html + '┗━<span style="width: 21px;display: inline-block;"><i onclick="getchildren(this)"></i></span>'+ ret.list[i]['uid'] +'<input class="uids" type="hidden" name="uids[]" value="'+ ret.list[i]['uid'] +'"></td>';
								html +='<td>' + nbsp_html + '┗━'+ ret.list[i]['user'] +'</td>';
								html +='<td class="grouptd"><span class="group" val="'+ ret.list[i]['uid'] +'">'+ ret.list[i]['title'] +'</span></td>';
								html +='<td class="center">'+ (ret.list[i]['phone']==''?default_con:ret.list[i]['phone']) +'</td>';
								html +='<td class="center">'+ (ret.list[i]['qq']==''?default_con:ret.list[i]['qq']) +'</td>';
								html +='<td class="center">'+ account_type_font +'</td>';
								html +='<td class="center">'+ (ret.list[i]['truename']==''?default_con:ret.list[i]['truename']) +'</td>';
								html +='<td class="center">'+ (ret.list[i]['alipay']==''?default_con:ret.list[i]['alipay']) +'</td>';
								html +='<td class="center">'+ ret.list[i]['money'] +'</td>';
								html +='<td class="center">'+ ret.list[i]['proportion'] +'%</td>';
								html +='<td class="center">'+ ret.list[i]['date'] +'</td>';
								html +='<td class="center">'+ lock_font +'</td>';
								html +='<td class="center">'+ hierarchy_font +'</td>';
								
								html +='<td class="center">';
								html +='<a class="hierarchy_default hierarchy_fine" href="{:U("Stats/order")}?uid='+ ret.list[i]['uid'] +'"><i class="fa fa-bar-chart-o"></i>&nbsp;数据统计</a>';
								html +='&nbsp;&nbsp;&nbsp;<div class="btn-group" style="vertical-align: top;"><a class="hierarchy_default hierarchy_fine" data-toggle="dropdown" aria-expanded="false">更多 <span class="caret"></span></a>';
								html +='<ul class="dropdown-menu dropdown-menu-right">';
								//html +='<li><a href="/backend/referral_links/index?uid='+ ret.list[i]['uid'] +'"><i class="fa fa-list"></i> 推广链接</a></li>';										
								//html +='<li class="divider"></li>';
								html +='<li><a href="{:U("edit")}?uid='+ ret.list[i]['uid'] +'"><i class="fa fa-edit"></i> 修改资料</a></li>';
								html +='<li class="divider"></li>';
								html +='<li><a data-id="'+ ret.list[i]['uid'] +'" data-name="'+ ret.list[i]['user'] +'" data-toggle="reset-password" href="#" class="text-danger reset_pass" onclick="reset_password(this)"><i class="fa fa-key"></i> 重置密码</a></li>';
								html +=lock_set_font;				
								html +='</ul></div></td></tr>';
							}
							
							t.after(html);
							$("." + id + "_child").show();
							t.removeClass('c_hide').addClass('c_open');
						});
			}
		} else{
			if (child.length > 0) {
				child.map(function(){
					var child_id = $(this).attr('data-id');
					var child_tr = $(".child_" + child_id);
					child_tr.hide();
					$(this).removeClass('c_open').addClass('c_hide');
				});
				child.hide();
				t.removeClass('c_open').addClass('c_hide');
			}
		}
	}
	
	/**
	* 锁定帐号
	**/
	function set_lock(uid, value){
		$.post("{:U('lock')}" , {uid :uid , value : value} , function(data){

			if(data.status ==  1){

				layer.alert(data.msg , function(){
					window.location.reload();
				});
			}else{

				layer.alert(data.msg);

			}

		},'json')
	}
	
	/**
	* 重置密码
	**/
	function reset_password(obj){
		$("#myModal").modal({});
		var name = $(obj).attr('data-name');
		$("#myModalLabel").text("重置密码");
		$(".modal-body").html("<span style='line-height: 50px;'>确定要重置 "+name+" 的密码吗?</span>");
		$('#myModal .btn_ok').unbind('click');
		$('#myModal .btn_un').show();
		$('#myModal .btn_ok').click(function(){
			$('#myModal .btn_ok').unbind('click');
			uid=$(obj).attr('data-id');
			$.post("{:U('resetpass')}" , {uid :uid } , function(data){
				setTimeout(function(){
					$("#myModal").modal({});
					var title = "密码重置失败";
					var cont = data.msg;
					if(data.state != 0){
						title = "密码重置成功";
						cont = "新密码只显示一次，请现在复制:<br/><font style='color: #05a7cc;font-size: 24px;text-align: center;display: block;'>"+data.data+"</font>";
					}
					$('#myModal .btn_un').hide();
					$("#myModalLabel").text(title);
					$(".modal-body").html("<span style='line-height: 50px;'>"+cont+"</span>");
				},500);
			},'json');
		});
	}
</script>
</body>
</html>
